package com.pla.googlecalendarviews;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.wonderly.awt.Packer;

public class AboutDialog extends JDialog {

  private final String homePage = "http://patrickarchibald.com/GoogleCalendarViews";
  private JButton okButton = new JButton("OK");
  private JButton goButton = new JButton("More info");
  private final String aboutText = "<html><p>Google Calendar Views helps you manage your calendar views.<br>If you have lots of calendars this application is for you.<br>You can create views displaying similiar groups of calendars.<br>Arrange them any way you like. <br>To get started add your Google accounts. Then create your views.<br>Call this program up when you want to switch views.<br>Be sure to refresh your browser (F5) after applying a new view.</html>";

  public static void main(String[] args) {
    Utils.setLookAndFeel();
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    new AboutDialog(frame);
  }

  public AboutDialog(JFrame parent) {
    super(parent);
    setTitle("About Google Calendar Views");
    setModal(true);
    JPanel panel = new JPanel();
    Packer packer = new Packer(panel);
    setContentPane(panel);
    Utils.makeDisposeOnEscapeKey(this);
    int y = 0;
    JLabel iconLabel = new JLabel();
    iconLabel.setIcon(Utils.getIcon("calendarSplash.png"));
    packer.pack(iconLabel).gridx(0).gridy(y++);
    packer.pack(new JLabel(aboutText)).gridx(0).gridy(y++);
    packer.pack(goButton).gridx(0).gridy(y++);
    packer.pack(okButton).gridx(0).gridy(y++);
    okButton.setMnemonic(KeyEvent.VK_K);
    goButton.setMnemonic(KeyEvent.VK_I);
    okButton.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent e) {
        dispose();
      }
    });
    goButton.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent e) {
        BrowserLaunch.openURL(homePage);
      }
    });
    pack();
    setLocationRelativeTo(parent);
    setVisible(true);
  }
}
